package com.yaozheng.vocationaltraining.service.impl;

import java.util.HashMap;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

import com.yaozheng.vocationaltraining.iview.IBaseView;
import com.yaozheng.vocationaltraining.service.LoginService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

/**
 * 登录服务实现
 * 
 * @author Administrator
 * 
 */
@EBean
public class LoginServiceImpl implements LoginService {
	private IBaseView iBaseView;

	@Override
	public void init(IBaseView iBaseView) {
		this.iBaseView = iBaseView;
	}

	@Background
	@Override
	public void doLogin(String userName, String passWord) {
		try {
			HashMap<String, String> para = new HashMap<String, String>();
			para.put("username", userName);
			para.put("password", passWord);
			OkHttpClientManager.getInstance().post(
					Constants.ROOTURL + "/user/login", null, para, iBaseView);
		} catch (Exception e) {
			ErrorUtils.outErrorLog(e);
			if (iBaseView.isResponseResult()) {
				iBaseView.responseError(ErrorUtils.SERVER_CONNECTION_ERROR);
			}

		}
	}

}
